package me.moscrop.RootCommand.commands;

import java.util.HashMap;
import java.util.Map;

import org.bukkit.Location;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

public class Back {
	
	//Store locations
	public static Map<String,Location> positions = new HashMap<String,Location>();

	//Method for when some runs the /back command
	public static boolean back(CommandSender sender)
	{
		//check command user is person
		if((sender instanceof Player) == false)
		{
			sender.sendMessage("This isnt a command for the console silly.");
			return true;
		}
		
		//check they have died on this server
		if(positions.containsKey(sender.getName()) == true)
		{
			sender.sendMessage("Welcome to your last grave.");
			//Move them to there last location
			((Player) sender).teleport((Location) positions.get(sender.getName()));
			return true;
		}else{
			//Tell them they have not died
			sender.sendMessage("Sorry, you havent died yet.");
			return true;
		}
		
	}
	
	public static void saveLastLocation(Player player, Location location) {
		positions.put(player.getName() , location.clone());
	}
	
}
